package cn.wei.youvierpc.serializer;

import cn.wei.youvierpc.spi.SpiLoader;

import java.util.HashMap;
import java.util.Map;

public class SerializerFactory {

    static {
        SpiLoader.load(Serializer.class);
    }

    /*使用spi方式记载
    private static final Map<String, Serializer> KEY_SERIALIZER_MAP = new HashMap<>() {{
       put(SerializerKeys.JDK, new JdkSerializer());
       put(SerializerKeys.JSON, new JsonSerializer());
       put(SerializerKeys.KRYO, new KryoSerializer());
       put(SerializerKeys.HESSIAN, new HessianSerializer());
    }};
    public static Serializer getInstance(String key) {
        return KEY_SERIALIZER_MAP.getOrDefault(key, DEFAULT_SERIALIZER);
    }*/
    private static final Serializer DEFAULT_SERIALIZER = new JdkSerializer();

    public static Serializer getInstance (String key) {
        return SpiLoader.getInstance(Serializer.class, key);
    }

}
